home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Information / CSMP Digest / volume 3 / csmp-digest-v3-056 < prev    next >
Text File  |  1995-12-31  |  57KB  |  1,446 lines

  1. Received-Date: Sat, 10 Sep 1994 13:05:34 +0200
  2. From: pottier@clipper.ens.fr (Francois Pottier)
  3. Subject: csmp-digest-v3-056
  4. To: csmp-digest@ens.fr
  5. Date: Sat, 10 Sep 1994 13:05:29 +0200 (MET DST)
  6. X-Mailer: ELM [version 2.4 PL23]
  7. Mime-Version: 1.0
  8. Content-Type: text/plain; charset=ISO-8859-1
  9. Content-Transfer-Encoding: 8bit
  10. Errors-To: listman@ens.fr
  11. Reply-To: pottier@clipper.ens.fr
  12. X-Sequence: 61
  13.  
  14. C.S.M.P. Digest             Sat, 10 Sep 94       Volume 3 : Issue 56
  15.  
  16. Today's Topics:
  17.  
  18.         A tool I could REALLY use, written it?
  19.         Async FileMgr Calls
  20.         Future of ASLM
  21.         Review of PowerMac devtools available
  22.         SetDialogDefaultItem() not doing anything!
  23.         Trouble making floating windows work with modeless dialogs
  24.  
  25.  
  26.  
  27. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  28. (pottier@clipper.ens.fr).
  29.  
  30. The digest is a collection of article threads from the internet newsgroup
  31. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  32. regularly and want an archive of the discussions.  If you don't know what a
  33. newsgroup is, you probably don't have access to it.  Ask your systems
  34. administrator(s) for details.  If you don't have access to news, you may
  35. still be able to post messages to the group by using a mail server like
  36. anon.penet.fi (mail help@anon.penet.fi for more information).
  37.  
  38. Each issue of the digest contains one or more sets of articles (called
  39. threads), with each set corresponding to a 'discussion' of a particular
  40. subject.  The articles are not edited; all articles included in this digest
  41. are in their original posted form (as received by our news server at
  42. nef.ens.fr).  Article threads are not added to the digest until the last
  43. article added to the thread is at least two weeks old (this is to ensure that
  44. the thread is dead before adding it to the digest).  Article threads that
  45. consist of only one message are generally not included in the digest.
  46.  
  47. The digest is officially distributed by two means, by email and ftp.
  48.  
  49. If you want to receive the digest by mail, send email to listserv@ens.fr
  50. with no subject and one of the following commands as body:
  51.     help                        Sends you a summary of commands
  52.     subscribe csmp-digest Your Name    Adds you to the mailing list
  53.     signoff csmp-digest            Removes you from the list
  54. Once you have subscribed, you will automatically receive each new
  55. issue as it is created.
  56.  
  57. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  58. Questions related to the ftp site should be directed to
  59. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  60. digest are available there.
  61.  
  62. Also, the digests are available to WAIS users.  To search back issues
  63. with WAIS, use comp.sys.mac.programmer.src. With Mosaic, use
  64. http://www.wais.com/wais-dbs/comp.sys.mac.programmer.html.
  65.  
  66.  
  67. -------------------------------------------------------
  68.  
  69. >From Chris Russo <chris@sonicsys.com>
  70. Subject: A tool I could REALLY use, written it?
  71. Date: 24 Aug 1994 16:57:56 GMT
  72. Organization: Sonic Systems, Inc.
  73.  
  74. While tracking down a nasty memory leak yesterday, I thought of something that
  75. would have been REALLY helpful.  What if I patched NewHandle() so that
  76. whenever it was called it would traipse over to the end of my routine and grab
  77. the Debugger info, then tacked it onto the rear of the handle?
  78.  
  79. That way, I could look at all of those loose memory fragments from ZoneRanger
  80. and determine instantly from where they had been allocated.
  81.  
  82. I started working on the thing yesterday, and spent a couple of hours on it.
  83. I wrote patches for NewHandle(), GetHandleSize(), and SetHandleSize().  Those
  84. last two would naturally have to be patched to make the debugging info
  85. transparent to the calling application.
  86.  
  87. Unfortunately, the routines aren't quite working and tend to crash.  More
  88. unfortunately, I don't have the time to keep working on them. :-(
  89.  
  90. If anyone's already written such a patch, <whoops> please let me know how it
  91. went and if I could have it.
  92.  
  93. If anyone would like to take this idea and run with it, by all means do so. 
  94. You can even have the source that I started.  There might be some issues
  95. involving the application's trap dispatch table that I'm not dealing with
  96. properly.  I've never really taken the time to learn that much about it, but
  97. would be happy to learn where I went awry.
  98.  
  99. btw, I have seen the leaks dcmd and don't really like to use it much.  From
  100. ZoneRanger, I can usually tell which memory blocks are useless, but it's hard
  101. to correlate those to the ones captured in leaks.  On top of that, leaks
  102. crashes my version of TMON.
  103.  
  104. Once again, if anyone wants to continue my effort, let me know.
  105.  
  106. - ------------------------------------------------------------------------
  107. Chris Russo                      Macintosh Programmer
  108. Sonic Systems, Inc.              (408) 736-1900 #107
  109. chris@sonicsys.com               NEVER respond to flame bait!
  110.  
  111. +++++++++++++++++++++++++++
  112.  
  113. >From onyxtech@aol.com (OnyxTech)
  114. Date: 26 Aug 1994 17:43:03 -0400
  115. Organization: America Online, Inc. (1-800-827-6364)
  116.  
  117. In article <33fu6k$f5s@news.internex.net>, Chris Russo
  118. <chris@sonicsys.com> writes:
  119.  
  120. >While tracking down a nasty memory leak yesterday, I thought of
  121. >something that would have been REALLY helpful.  What if I patched
  122. >NewHandle() so that whenever it was called it would traipse over to
  123. >the end of my routine and grab the Debugger info, then tacked it onto
  124. >the rear of the handle?
  125. >That way, I could look at all of those loose memory fragments from
  126. >ZoneRanger and determine instantly from where they had been allocated.
  127.  
  128. Mmmm.  There is a version of QC(tm) that has similar leaks detection (you
  129. can use sym files as well) that will follow a native PowerPC upgrade ahead
  130. of it in the pipeline.  We are working on graphical representation of heap
  131. allocations and deletions and hope to create some sort of published
  132. interface so tools like ZoneRanger can use our data to represent more
  133. information to users.  After all, why should we re-create ZoneRanger type
  134. utilities when they've already done all the work.  We just need to help
  135. them get at more information.
  136.  
  137. If you'd like me to keep you (and whomever else is reading this) abreast
  138. of this new version of QC, drop us a line at 'onyxtech@aol.com'.
  139.  
  140. dEVoN Hubbard
  141. Onyx Technology
  142.  
  143. +++++++++++++++++++++++++++
  144.  
  145. >From h+@nada.kth.se (Jon W{tte)
  146. Date: Sat, 27 Aug 1994 15:52:17 +0200
  147. Organization: Royal Institute of Something or other
  148.  
  149. In article <33fu6k$f5s@news.internex.net>,
  150. Chris Russo <chris@sonicsys.com> wrote:
  151.  
  152. >While tracking down a nasty memory leak yesterday, I thought of something that
  153. >would have been REALLY helpful.  What if I patched NewHandle() so that
  154. >whenever it was called it would traipse over to the end of my routine and grab
  155. >the Debugger info, then tacked it onto the rear of the handle?
  156. >
  157. >That way, I could look at all of those loose memory fragments from ZoneRanger
  158. >and determine instantly from where they had been allocated.
  159.  
  160. It's easier to just install the "leaks" MacsBug dcmd. I don't 
  161. know whether it will still work with the new memroy manager 
  162. though. Anyone else know?
  163.  
  164. Another thing you can do is to replace all your calls to 
  165. NewHandle() etc with MyNewHandle() and have non-patches that 
  166. did the tracking work; you could even define MyNewHandle to 
  167. pass source file and line number information using __FILE__ and 
  168. __LINE__. Then when you compile the release version, you just 
  169. define MyNewHandle() to NewHandle().
  170.  
  171. This is great for validating memory as well; you can have a 
  172. validation routine that traverses all of your dynamically 
  173. allocated memory and checks it against a list you keep; if 
  174. something's not checked on the list, you have a leak. If a 
  175. pointer/handle is not on the list, you have a dangling 
  176. pointer/handle.
  177.  
  178. Cheers,
  179.  
  180.                 / h+
  181.  
  182.  
  183. --
  184.   Jon W‰tte (h+@nada.kth.se), Hagagatan 1, 113 48 Stockholm, Sweden
  185.     Not speaking for IBM.
  186.  
  187.  
  188. ---------------------------
  189.  
  190. >From chris-b@cs.auckland.ac.nz (Chris Burns)
  191. Subject: Async FileMgr Calls
  192. Date: Sat, 20 Aug 1994 00:58:02 +1200
  193. Organization: AucklandUniversity:ComputerScience:HMU
  194.  
  195. Hi All,
  196.  
  197. I've been looking into using async file manager calls, so I started
  198. experimenting with an easy one, an indexed _PBHGetVgreatly appreciated.
  199.  
  200. Thanks In Advance,
  201.  
  202. Chris B
  203. - ---------------------------------------------------------------------
  204. NewZealand:AucklandUniversity:ComputerScience:HyperMediaUnit:ChrisBurns
  205. Internet: chris-b@cs.auckland.ac.nz
  206. Phone:    +64 9 373-7599 x6194
  207. Fax:      +64 9 373-7453                         Async, therefore I am.
  208. - ---------------------------------------------------------------------
  209.  
  210. +++++++++++++++++++++++++++
  211.  
  212. >From h+@nada.kth.se (Jon W{tte)
  213. Date: Fri, 19 Aug 1994 22:27:16 +0200
  214. Organization: Royal Institute of Something or other
  215.  
  216. In article <chris-b-2008940058020001@hmu7.cs.aukuni.ac.nz>,
  217. chris-b@cs.auckland.ac.nz (Chris Burns) wrote:
  218.  
  219. >version (MW C/C++ PPC 1.01 DR/3.5) is the one that works correctly. The
  220. >68K version however, does not work. The _PBHGetVInfoAsync call returns all
  221. >kinds of bogus values instead of nice file manager errors.
  222.  
  223. That's because you're testing the return value of an asynchronous
  224. call. You're not supposed to do that, since there's no error to
  225. return there yet; instead you're supposed to test ioResult in the
  226. completion proc, or poll ioResult until it's not 1.
  227.  
  228. Cheers,
  229.  
  230.                 / h+
  231.  
  232.  
  233. --
  234.   Jon W‰tte (h+@nada.kth.se), Hagagatan 1, 113 48 Stockholm, Sweden
  235.  
  236. "TextEdit does everything right."
  237.     ã Jon W{tte
  238.  
  239.  
  240. +++++++++++++++++++++++++++
  241.  
  242. >From chris-b@cs.auckland.ac.nz (Chris Burns)
  243. Date: Sun, 21 Aug 1994 18:19:12 +1200
  244. Organization: AucklandUniversity:ComputerScience:HMU
  245.  
  246. In article <9668AA7AE244.44E5E@klkmac004.nada.kth.se>, h+@nada.kth.se (Jon
  247. W{tte) wrote:
  248.  
  249. > In article <chris-b-2008940058020001@hmu7.cs.aukuni.ac.nz>,
  250. > chris-b@cs.auckland.ac.nz (Chris Burns) wrote:
  251. > >version (MW C/C++ PPC 1.01 DR/3.5) is the one that works correctly. The
  252. > >68K version however, does not work. The _PBHGetVInfoAsync call returns all
  253. > >kinds of bogus values instead of nice file manager errors.
  254. > That's because you're testing the return value of an asynchronous
  255. > call. You're not supposed to do that, since there's no error to
  256. > return there yet; instead you're supposed to test ioResult in the
  257. > completion proc, or poll ioResult until it's not 1.
  258.  
  259. Sorry Jon, I don't buy it.
  260.  
  261. (I'm assuming that IM-IV Chpt 19 [File Manager] is still valid because it
  262. documents the low-level file manager routines; I havn't looked at
  263. NIM:Files)
  264.  
  265. Check out IM-IV Pg 119:
  266.  
  267. "Routines that are executed asynchronously return control to the calling
  268. program with the result code noErr as soon as the call is placed in the
  269. file I/O queue. This isn't an indication of successful call completion,
  270. but simply indicates that the call was successfully queued."
  271.  
  272. This is the case with nearly all async calls, they return a file manager
  273. error to the calling program (typically "noErr", but possibly "paramErr"
  274. or others), and then the real error somewhere in the param block (often
  275. also in D0) at completion proc time. These two errors should not be
  276. related in any way. The fact that D0 = $stuvwxyz upon exit of the
  277. completion proc should not mean that the calling code receives an error of
  278. $wxyz (D0.w).
  279.  
  280. IM-IV Pg 119:
  281.  
  282. "Warning: Completion routines are executed at interrupt level and must
  283. preserve all registers other than A0,A1, and D0-D2."
  284.  
  285. Surely this means my completion routine code can do what it wants with
  286. these regs without affecting anything.
  287.  
  288. IM-IV Pg 119:
  289.  
  290. "When your completion routine is called, register A0 points to the
  291. parameter block of the asynchronous call and register D0 contains the
  292. result code."
  293.  
  294. I read this to mean that these were "read-only" values (changes are not
  295. propagated back to calling code). I based this upon the fact that the
  296. completion proc may be called _well_ after the _PBHGetVInfo call. A remote
  297. file system such as an AppleShare volume will definitely be this way for
  298. mnay types of calls.
  299.  
  300.  
  301. I have kind-of solved this problem, but not to my satisfaction. If I save
  302. and restore the scratch regs (A0,A1, and D0-D2) the thing works properly.
  303. However, I don't think I should need to do this, and besides, its real
  304. ugly.
  305.  
  306. #if USES68KINLINES
  307. asm....
  308. #endif
  309.  
  310. yuck!
  311.  
  312. Any more ideas would be wonderful.
  313.  
  314. Thanks Heaps In Advance,
  315.  
  316. Chris B
  317. - ---------------------------------------------------------------------
  318. NewZealand:AucklandUniversity:ComputerScience:HyperMediaUnit:ChrisBurns
  319. Internet: chris-b@cs.auckland.ac.nz
  320. Phone:    +64 9 373-7599 x6194
  321. Fax:      +64 9 373-7453                         Async, therefore I am.
  322. - ---------------------------------------------------------------------
  323.  
  324. +++++++++++++++++++++++++++
  325.  
  326. >From Jaeger@fquest.com (Brian Stern)
  327. Date: 21 Aug 1994 14:39:41 GMT
  328. Organization: The University of Texas at Austin, Austin, Texas
  329.  
  330. In article <chris-b-2008940058020001@hmu7.cs.aukuni.ac.nz>,
  331. chris-b@cs.auckland.ac.nz wrote:
  332.  
  333. > Hi All,
  334. > I've been looking into using async file manager calls, so I started
  335. > experimenting with an easy one, an indexed _PBHGetVInfoAsync call until
  336. > the error returned is nsvErr (no-such-volume: -35). This works perfectly
  337. > using sync calls. Things aren't so rosy on the async front tho'.
  338. > Being in a PowerPC friendly kind of mood (and running on a PM8100/80), I
  339. > thought "cool, I'll use UPPs for my completion routine specifiers, and
  340. > compile a fat app". This aspect is fine, and in fact, the PowerPC native
  341. > version (MW C/C++ PPC 1.01 DR/3.5) is the one that works correctly. The
  342. > 68K version however, does not work. The _PBHGetVInfoAsync call returns all
  343. > kinds of bogus values instead of nice file manager errors.
  344. > Here's the entire code:
  345. > #if USES68KINLINES
  346. > #pragma parameter CompletionProc(__A0)
  347. > #endif
  348. > pascal void CompletionProc(HParmBlkPtr HPB)
  349. > {
  350. > long SavedA5 = SetA5(((VolPBPtr)HPB)->AppA5);
  351. >     gNumDrivesDone++;
  352. >     DebugStr(((VolPBPtr)HPB)->VolName);
  353. >     SetA5(SavedA5);
  354. > }
  355. > Chris B
  356. > -----------------------------------------------------------------------
  357. > NewZealand:AucklandUniversity:ComputerScience:HyperMediaUnit:ChrisBurns
  358. > Internet: chris-b@cs.auckland.ac.nz
  359. > Phone:    +64 9 373-7599 x6194
  360. > Fax:      +64 9 373-7453                         Async, therefore I am.
  361. > -----------------------------------------------------------------------
  362.  
  363. So why not change it to this:
  364.  
  365. #if USES68KINLINES
  366. #pragma parameter __D0 CompletionProc(__A0)
  367. #endif
  368.  
  369. pascal OSErr CompletionProc(HParmBlkPtr HPB)
  370. {
  371. long SavedA5 = SetA5(((VolPBPtr)HPB)->AppA5);
  372.  
  373.     gNumDrivesDone++;
  374.     DebugStr(((VolPBPtr)HPB)->VolName);
  375.  
  376.     SetA5(SavedA5);
  377.  
  378.     return HPB->ioResult;
  379.  
  380. }
  381.  
  382. No Assembly Required.
  383.  
  384. My reading of the passages in IM-IV that you quoted seems ambiguous about
  385. whether or not a completion routine returns a result in DO.  My first
  386. guess would have been no.
  387.  
  388. BTW, Use of the #pragma parameter in this way in MW works differently from
  389. Think C.  In Think you can only use #pragma parameter for inline calls. 
  390. This means that it's only useful for routines that you're calling, not for
  391. cases where your routines are called with parameters in registers.  So
  392. when compiling your CompletionProc with Think C, the compiler ignores the
  393. #pragma parameter and assumes that HPB was passed on the stack.  Oh well 
  394. :-(
  395.  
  396. -- 
  397. Brian  Stern  :-{)}
  398. Jaeger@fquest.com
  399.  
  400. +++++++++++++++++++++++++++
  401.  
  402. >From resnick@uiuc.edu (Pete Resnick)
  403. Date: Sun, 21 Aug 1994 13:02:57 -0500
  404. Organization: University of Illinois at Urbana-Champaign
  405.  
  406. In article <9668AA7AE244.44E5E@klkmac004.nada.kth.se>, h+@nada.kth.se (Jon
  407. W{tte) wrote:
  408.  
  409. >That's because you're testing the return value of an asynchronous
  410. >call. You're not supposed to do that, since there's no error to
  411. >return there yet; instead you're supposed to test ioResult in the
  412. >completion proc, or poll ioResult until it's not 1.
  413.  
  414. No, you're wrong. Inside Macintosh: Files, page 2-6 is quite explicit:
  415.  
  416.     Routines that are executed asynchronously return control to your
  417.     application with the result code noErr as soon as the call is placed in
  418.     the file I/O queue. Return of control does not signal successful
  419.     completion of the call, but simply successful queuing of the request.
  420.  
  421. You could plausibly get back an error if for some reason the Device
  422. Manager determined that the call could not be queued (a screwy refNum or
  423. the like). You are perfectly correct (though maybe using a little
  424. overkill) in checking the return code from an asynchronous routine. The
  425. problem lies somewhere else.
  426.  
  427. pr
  428. -- 
  429. Pete Resnick        (...so what is a mojo, and why would one be rising?)
  430. Doctoral Student - Philosophy Department, Gregory Hall, UIUC
  431. System manager - Cognitive Science Group, Beckman Institute, UIUC
  432. Internet: resnick@uiuc.edu
  433.  
  434. +++++++++++++++++++++++++++
  435.  
  436. >From benh@fdn.org (Benjamin Herrenschmidt)
  437. Date: Mon, 22 Aug 94 11:52:45 +0100
  438. Organization: (none)
  439.  
  440.  
  441.  
  442. >>That's because you're testing the return value of an asynchronous
  443. >>call. You're not supposed to do that, since there's no error to
  444. >>return there yet; instead you're supposed to test ioResult in the
  445. >>completion proc, or poll ioResult until it's not 1.
  446. >
  447. >No, you're wrong. Inside Macintosh: Files, page 2-6 is quite explicit:
  448. >
  449. >    Routines that are executed asynchronously return control to your
  450. >    application with the result code noErr as soon as the call is placed in
  451. >    the file I/O queue. Return of control does not signal successful
  452. >    completion of the call, but simply successful queuing of the request.
  453. >
  454. >You could plausibly get back an error if for some reason the Device
  455. >Manager determined that the call could not be queued (a screwy refNum or
  456. >the like). You are perfectly correct (though maybe using a little
  457. >overkill) in checking the return code from an asynchronous routine. The
  458. >problem lies somewhere else.
  459.  
  460. I remember something about async File Mgr. calls : unlike device manager
  461. calls, File Manager calls ALWAYS calls the completion routine to handle
  462. the result code, and the result of the async call itself MAY be garbage,
  463. event if something is wrong with the queue. The result code you should
  464. use is the one returned to the completion routine (or in the ioResult
  465. field of the paramblock)
  466.  
  467. I think i read this in a technote or a Q&A... 
  468.  
  469. BenH.
  470.  
  471. +++++++++++++++++++++++++++
  472.  
  473. >From ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  474. Date: 23 Aug 94 18:05:13 +1200
  475. Organization: University of Waikato, Hamilton, New Zealand
  476.  
  477. In article <chris-b-2108941819120001@hmu7.cs.aukuni.ac.nz>, chris-b@cs.auckland.ac.nz (Chris Burns) writes:
  478. > In article <9668AA7AE244.44E5E@klkmac004.nada.kth.se>, h+@nada.kth.se (Jon
  479. > W{tte) wrote:
  480. >
  481. >> In article <chris-b-2008940058020001@hmu7.cs.aukuni.ac.nz>,
  482. >> chris-b@cs.auckland.ac.nz (Chris Burns) wrote:
  483. >>
  484. >> That's because you're testing the return value of an asynchronous
  485. >> call. You're not supposed to do that, since there's no error to
  486. >> return there yet; instead you're supposed to test ioResult in the
  487. >> completion proc, or poll ioResult until it's not 1.
  488. >
  489. > Sorry Jon, I don't buy it.
  490. >
  491. > (I'm assuming that IM-IV Chpt 19 [File Manager] is still valid because it
  492. > documents the low-level file manager routines; I havn't looked at
  493. > NIM:Files)
  494. >
  495. > Check out IM-IV Pg 119:
  496. >
  497. > "Routines that are executed asynchronously return control to the calling
  498. > program with the result code noErr as soon as the call is placed in the
  499. > file I/O queue. This isn't an indication of successful call completion,
  500. > but simply indicates that the call was successfully queued."
  501.  
  502. There is a technote somewhere which corrects this. Basically, you shouldn't
  503. bother checking the immediate return code from _any_ async call. I recently
  504. got burned with this doing async sound recording: my call to SPBRecord worked
  505. fine everywhere _except_ on a 500-series PowerBook, and then only when I
  506. invoked a combination of certain other recording options at the same time.
  507.  
  508. There is one situation where you should be careful about polling ioResult
  509. (And I'm not talking about being stupid, sitting in a tight loop at interrupt
  510. level, blocking the completion of the call you're polling for!): the PPC
  511. Toolbox. In System 7.0, the PPC Toolbox sets ioResult some time before it
  512. dequeues the parameter block from its request queue. This means if you have
  513. an interrupt routine that periodically checks the ioResult from a PPC Toolbox
  514. request, and assumes the parameter block can be reused the moment it goes 0
  515. or negative, you could be in for a crash. If you specify a completion routine,
  516. then the parameter block can be safely reused when this routine is called.
  517.  
  518. I understand this might be fixed in later Systems, but I'm not sure which ones.
  519. If Jim Luther is reading this, he might be able to update us...
  520.  
  521. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  522. Info & Tech Services Division              fax: +64-7-838-4066
  523. University of Waikato            electric mail: ldo@waikato.ac.nz
  524. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00
  525.  
  526. +++++++++++++++++++++++++++
  527.  
  528. >From chris-b@cs.auckland.ac.nz (Chris Burns)
  529. Date: Wed, 24 Aug 1994 12:47:36 +1200
  530. Organization: AucklandUniversity:ComputerScience:HMU
  531.  
  532. In article <Jaeger-2108940941410001@slip-1-88.ots.utexas.edu>,
  533. Jaeger@fquest.com (Brian Stern) wrote:
  534.  
  535. > So why not change it to this:
  536. > #if USES68KINLINES
  537. > #pragma parameter __D0 CompletionProc(__A0)
  538. > #endif
  539. > pascal OSErr CompletionProc(HParmBlkPtr HPB)
  540. > {
  541. > long SavedA5 = SetA5(((VolPBPtr)HPB)->AppA5);
  542. >     gNumDrivesDone++;
  543. >     DebugStr(((VolPBPtr)HPB)->VolName);
  544. >     SetA5(SavedA5);
  545. >     return HPB->ioResult;
  546. > }
  547. > No Assembly Required.
  548.  
  549. Yeah, good idea Brian. This actually works on both platforms and does not
  550. use any asm. Thanks for the idea, I'll end up using this.
  551.  
  552. It should not be required tho'. Apple docs clearly state that D0 doesn't
  553. have to be save/restored and don't say the error should be returned in D0
  554. either (in fact this cannot be the case because the completion proc could
  555. potentially execute _well after_ the original error has been returned.
  556. Maybe this call cannot be done truely async?
  557.  
  558. Thanks Again,
  559.  
  560. Chris B
  561. - ---------------------------------------------------------------------
  562. NewZealand:AucklandUniversity:ComputerScience:HyperMediaUnit:ChrisBurns
  563. Internet: chris-b@cs.auckland.ac.nz
  564. Phone:    +64 9 373-7599 x6194
  565. Fax:      +64 9 373-7453                         Async, therefore I am.
  566. - ---------------------------------------------------------------------
  567.  
  568. +++++++++++++++++++++++++++
  569.  
  570. >From Clinton Bauder <gecko1@applelink.apple.com>
  571. Date: Wed, 24 Aug 1994 21:02:10 GMT
  572. Organization: Apple Computer Inc.
  573.  
  574. In article <chris-b-2008940058020001@hmu7.cs.aukuni.ac.nz> Chris Burns,
  575. chris-b@cs.auckland.ac.nz writes:
  576. >
  577. >        Err = PBHGetVInfoAsync((HParmBlkPtr)VPB);
  578. >
  579. >        switch (Err)
  580. >        {
  581. >            case noErr:
  582. >                break;
  583. >
  584. >            case nsvErr:
  585. >                continue;
  586. >
  587. >            default:
  588. >                DebugStr("\p_PBHGetVInfoAsync FAILED");
  589. >                break;
  590. >        }
  591.  
  592. If you are making an async call you have to wait for it to complete.  A
  593. return of noErr from an async call doesn't mean it is done.  I merely
  594. means the PB was correctly filled out and has been accepted (queued) by
  595. the File Mananger.  At some later point it will be completed and the
  596. ioResult field will be updated with the correct result and the completion
  597. routine called.  Your application needs to either poll ioResult (wait til
  598. it is not 1 - which means in progress) or poll some other variable which
  599. is set by the completion routine.  To really take advantage of async IO
  600. you should try and do something with the time in between when you make
  601. the file system call and when ioResult changes to <= noErr.
  602.  
  603. Clinton
  604. - -------------------------------------------------------------
  605. Clinton Bauder        | Opinions expressed are very likely to
  606. SCSI Grunt and Chief  | be entirely different from the official
  607. Herpetoculturist      | party line of Apple Computer Inc.
  608. Apple Computer Inc.   | Support your local herp society.
  609. - -------------------------------------------------------------
  610.  
  611. +++++++++++++++++++++++++++
  612.  
  613. >From jumplong@aol.com (Jump Long)
  614. Date: 26 Aug 1994 01:42:07 -0400
  615. Organization: America Online, Inc. (1-800-827-6364)
  616.  
  617. In article <chris-b-2108941819120001@hmu7.cs.aukuni.ac.nz>,
  618. chris-b@cs.auckland.ac.nz (Chris Burns) writes:
  619.  
  620. >Any more ideas would be wonderful.
  621.  
  622. I responded to Chris via email with this:
  623.  
  624. - ---
  625.  
  626. Chris,
  627.  
  628. You need to get a copy of develop magazine issue #13 and read the article
  629. I wrote called "Asynchronous Routines on the Macintosh".  It answers many
  630. of your current questions and will answer many of the questions you're
  631. going to have in the future :-)  In many cases while writing that article,
  632. I found that Inside Mac was either wrong, or just didn't describe things
  633. completely.
  634.  
  635. Here's some specific information for what you observed.
  636.  
  637. 1) If the File Manager isn't busy when it receives a request (asynchronous
  638. or synchronous), it doesn't queue it - it begins execution of the request
  639. immediately. If the File Manager is busy handling another request, *then*
  640. the request is queued until the all requests before it in the queue have
  641. executed. If the request is a synchronous request, then the system spins
  642. in SyncWait waiting for the synchronous request to be executed. If the
  643. request is an asynchronous request and it is queued, then control is
  644. returned to the caller after the request is queued
  645.  
  646. 2) When the current request is finished executing and the File Manager has
  647. called its completion routine, the File Manager begins excution of the
  648. next request in the queue (if any).
  649.  
  650. 3) Once the File Manager starts executing an asynchronous request, it
  651. doesn't give up control until it is either: a) done handling the request
  652. or b) makes an asynchronous request to a device driver to read or write
  653. block(s) of data and the device driver returns control to the File Manager
  654. while it handles the request asynchronously. The part "while it handles
  655. the request asynchronously" is important because if the driver handles all
  656. requests synchronously (like the old SCSI Manager does), then the File
  657. Manager doesn't get control back from the driver call until it has
  658. completed, and in that case, the File Manager continues with the execution
  659. of the request.
  660.  
  661. So, when you call PBHGetVInfoAsync, if the File Manager isn't busy, it
  662. starts execution of the request immediately.  Since GetVInfo requests
  663. don't cause calls to the driver (unless you pass a working directory
  664. number instead of real volume reference number), there is nothing to stop
  665. the File Manager from completing the request. That's why you're seeing the
  666. request complete immediately.
  667.  
  668. The reason you're seeing the 5 you slam into DO in the completion routine
  669. is that the File Manager uses D0 to return function results to
  670. *synchronous* requests.  With an asynchronous request, you never know what
  671. the real result of the request is until it completes, so the File Manager
  672. sets D0 to 0 when it *starts* execution of the request and doesn't worry
  673. about returning the ioResult value (which is 1 while the call is queued or
  674. executing) to the caller. Here's how we (Apple) recommend making
  675. asychronous File Manager requests (note: Device Manager calls are handled
  676. differently - read the article):
  677.  
  678. /* Make an asynchronous request. */
  679. /* Ignore the function result and look for the */
  680. /* real result when the call completes. */
  681. (void) PBHGetVInfoAsync(&pb);
  682.  
  683. or in Pascal:
  684.  
  685. if (PBHGetVInfoAsync(@pb) <> noErr)
  686.   ; { do nothing, check result at completion }
  687.  
  688. - ---
  689.  
  690. - Jim Luther
  691.  
  692.  
  693. ---------------------------
  694.  
  695. >From bentley@MCS.COM (Mike Bentley)
  696. Subject: Future of ASLM
  697. Date: 13 Aug 1994 17:46:25 -0500
  698. Organization: MCSNet Subscriber Account, Chicago's First Public-Access Internet!
  699.  
  700. What I meant to ask was,
  701. after finally getting something like a shared library manager out for the 680x0
  702. machines, how does ASLM fit into the plan when building a shared library file
  703. with both 680x0 and PowerPC code in it?
  704.  
  705. My guess is that this doesn't happen, that an ASLM library gets a file and the
  706. equivalent code fragment import library (a 'shlb' -- too bad, 'shlp' is funnier)
  707. is a separate file. This probably means that there is some differences in
  708. implementation detail in the source code.
  709.  
  710. -Mike Bentley
  711. Crenelle Inc.
  712.  
  713.  
  714. +++++++++++++++++++++++++++
  715.  
  716. >From garryh@seeding.apple.com (Garry Hornbuckle)
  717. Date: 26 Aug 1994 18:39:45 GMT
  718. Organization: Apple Computer, Inc.
  719.  
  720. In article <32jig1$42k@Mercury.mcs.com>, bentley@MCS.COM (Mike Bentley) wrote:
  721.  
  722. > What I meant to ask was,
  723. > after finally getting something like a shared library manager out for
  724. the 680x0
  725. > machines, how does ASLM fit into the plan when building a shared library file
  726. > with both 680x0 and PowerPC code in it?
  727.  
  728. ==========================================
  729. Macintosh Dynamic Linked Libraries (DLLs)
  730. ==========================================
  731.  
  732. Apple has developed a complete technology solution for shared code, shared
  733. objects, and dynamic linked libraries (DLLs) on the Macintosh. Parts of
  734. this solution are available today, with additional parts becoming
  735. available in the coming months.
  736.  
  737. There are three key components to Macintosh DLL strategy:
  738. ĆApple's Shared Library Manager (ASLM),
  739. ĆApple's Code Fragment Manager (CFM), and
  740. ĆIBM's System Object Model (SOM).
  741.  
  742. Here is a brief summary of ASLM, CFM, and SOM ...
  743.  
  744. ASLM
  745. - ----------
  746. Apple Shared Library Manager is the first component of Apple's DLL
  747. solution to be available, and is an integral part of our overall DLL
  748. offering.  ASLM supports shared code libraries for both procedural and
  749. object oriented development efforts. A number of Apple products have
  750. already been based on ASLM, including MacSNMP and the GeoPort
  751. communications pod technology. Third parties such as Microsoft (OLE for
  752. Macintosh), Novell (AppWare), and Aldus have also adopted ASLM to support
  753. their DLL needs.
  754.  
  755. In the future, additonal functionality will be added to the Macintosh
  756. operating system as ASLM libraries, including our next generation
  757. networking, the Open Transport Communications Architecture.
  758.  
  759. ASLM v1.1.2 is the currently shipping release. ASLM v2.0 is under
  760. development, to provide support for native code shared libraries on Power
  761. Macintosh. ASLM 2.x sits on top of (is based on) the Code Fragment
  762. Manager. This work is expected to produce final product in 4Q CY94.
  763.  
  764. As CFM becomes available on 68K Macintosh (see below), a future ASLM
  765. version (2.1) will support CFM on 68K as well, while continuing to support
  766. current 68K-style shared libraries. Thus,  ASLM v2.x will provide
  767. compatibility for ASLM v1.1, v1.1.1, and v1.1.2 applications.
  768.  
  769. ASLM adds higher-level object-oriented capabilities to the environment
  770. that are not a part of the Code Fragment Manager itself. ASLM is the
  771. technology of choice when you:
  772.  
  773. Ä  need DLLs on 68K today ... ASLM is shipping
  774. Ä  want simplicity and elegance with C++
  775. Ä  want a simple but powerful extension mechanism using C, Pascal, or ASM
  776. Ä  have performance sensitive (i.e., interrupt time) needs like networking
  777. Ä  want run-time transparent dynamic loading and unloading of code
  778. Ä  DON'T need transparent access to per-context global data
  779. Ä  DON'T need to solve the "fragile base class" problem for C++
  780.  
  781. CFM
  782. - ----------
  783. As a second key step in our DLL strategy, Apple has developed a new
  784. foundation layer for dynamic linking on the Macintosh known as the Code
  785. Fragment Manager (CFM). CFM will be a core part of System Software on the
  786. PowerPC Macintosh.
  787.  
  788. CFM is also being developed for the Macintosh on 68K. This work is
  789. expected to produce final product in 1Q CY95.
  790.  
  791. The Code Fragment Manager provides code sharing and dynamic linking, with
  792. features supporting per-context globals. CFM will be fully supported by
  793. development tools on Macintosh.
  794.  
  795. CFM is the best bet when your application:
  796. Ä  runs on PowerPC Macintosh first, and 68K Macintosh later
  797. Ä  needs only basic dynamic loading and unloading of shared code
  798. Ä  needs to reduce system overhead to the minimum amount
  799. Ä  needs transparent access to per-context global data
  800. Ä  DOES NOT need system-level OOP support
  801.  
  802.  
  803. SOM
  804. - ----------
  805. Apple is in the process of licensing and porting IBM's System's Object
  806. Model (SOM) technology to Macintosh. SOM is a multi-platform standard
  807. providing for system-level sharable objects in a language-neutral way. SOM
  808. also solves the "fragile base class" problem, avoiding the need for client
  809. libraries to be recompiled when the base class they inherit from is in a
  810. different library and is changed.
  811.  
  812. To offer these benefits (multi-platform support and fragile base-class
  813. resolution) SOM requires the use of an IDL as a first step in the
  814. development process.
  815.  
  816. SOM runs on top of CFM, and thus will become available on both 68K and
  817. PowerPC Macintosh.
  818.  
  819. SOM is a foundation technology for OpenDoc. 
  820.  
  821.  
  822. Integration
  823. - ----------
  824. SOM and ASLM will both live in a CFM run-time environment, and will both
  825. be available on both 68K and PowerPC Macintosh. Thus there will be no
  826. impediment to co-existence of ASLM and SOM, or to applications that use
  827. both ASLM and SOM. In fact, a SOM class could easily call an ASLM class or
  828. vice-versa.
  829.  
  830. Over time, some of the functionality provided by ASLM may be supplanted by
  831. SOM. However, ASLM APIs will be preserved. As a result, applications
  832. written to the ASLM API may have some functionality transparently migrated
  833. to SOM in the future.
  834.  
  835. - -----------------------------------------------------------------
  836. Garry Hornbuckle    Product Manager, Communications & Collaboration
  837. - -----------------------------------------------------------------
  838. "If I told you that I   | email      garryh@seeding.apple.com
  839.  spoke only for myself  | applelink  HORNBUCKLE1
  840.  would you believe me?" | fax        (408) 974-1211
  841. - -----------------------------------------------------------------
  842.  
  843. ---------------------------
  844.  
  845. >From Jaeger@fquest.com (Brian Stern)
  846. Subject: Review of PowerMac devtools available
  847. Date: 26 Aug 1994 03:20:05 GMT
  848. Organization: The University of Texas at Austin, Austin, Texas
  849.  
  850. If you haven't come across it yet, there is an interesting article titled: 
  851.  
  852. PUTTING THE C(++) INTO POWER MACINTOSH by Jon Lansdell (August 19th 1994),
  853.  
  854. that has appeared in the current version of powerPC news.  It is the first
  855. part of a two part series that will review the four native development
  856. environments for the PowerMac.  In case you're wondering these are:
  857.  
  858. *Symantec's Cross Development kit*
  859. *MPW*
  860. *The Absoft C/C++ SDK* 
  861. *CodeWarrior *
  862.  
  863. Here are a few quotes taken completely out of context:
  864.  
  865. Symantec's image amongst the Macintosh developer community was somewhat
  866. tarnished by release 6.0 of Symantec C++ for the Macintosh and reports
  867. that it was somewhat buggy. 
  868.  
  869. MPW - tried, tested and old.  ETO#15 and the MPW Pro CD both contain
  870. pre-release native versions of the MPW Shell and various tools, including
  871. PPCC. While this does compile applications around twice as fast, the
  872. Linker still has to run under emulation, so while Apple work on a new
  873. native development environment, developers have plenty of time for coffee
  874. breaks during the build process. 
  875.  
  876. The Absoft SDK includes a couple of extras which give it claim to be a
  877. fully rounded development environment.  Although the Linker and Compiler
  878. are native, it does cry out to be part of a completely native development
  879. environment.
  880.  
  881. You can find the article via your favorite web-client at:
  882.  
  883. http://power.globalnews.com:8000/
  884.  
  885. -- 
  886. Brian  Stern  :-{)}
  887. Jaeger@fquest.com
  888.  
  889. ---------------------------
  890.  
  891. >From scotth@jaguar.visix.com (Scott Hofmann)
  892. Subject: SetDialogDefaultItem() not doing anything!
  893. Date: Thu, 25 Aug 1994 13:42:32 GMT
  894. Organization: Visix Software, Reston, Virginia
  895.  
  896. In some code I've written for a preferences dialog, I use the calls
  897. SetDialogDefaultItem() and SetDialogCancelItem() to make my "OK" and "Cancel"
  898. buttons look and perform according to Apple spec, but both traps aren't doing
  899. anything- it's like they exist, but are bound to no-op. This happens both in
  900. Symantec C++ 6.0, using the glue from the THINK Ref 2.0, and in Metrowerks CW4.
  901. I'm working on a Centris 650 running System 7.1, so I'm pretty sure my ROMs
  902. contain that trap - could I be mistaken about this? Has anyone use gotten these
  903. traps to work? Thanks,
  904.  
  905.                                                             scott
  906. -- 
  907. - -----------------------------------------------------------------------------
  908. J. Scott Hofmann                        | "You've saved humanity...once again"
  909. scotth@visix.com                        |       -Q to Capt. Picard, ST:TNG
  910.  
  911. +++++++++++++++++++++++++++
  912.  
  913. >From hanrek@cts.com (Mark Hanrek)
  914. Date: 25 Aug 1994 20:18:00 GMT
  915. Organization: The Information Workshop
  916.  
  917. In article <SCOTTH.94Aug25094232@jaguar.visix.com>,
  918. scotth@jaguar.visix.com (Scott Hofmann) wrote:
  919.  
  920. > In some code I've written for a preferences dialog, I use the calls
  921. > SetDialogDefaultItem() and SetDialogCancelItem() to make my "OK" and "Cancel"
  922. > buttons look and perform according to Apple spec, but both traps aren't doing
  923. > anything- it's like they exist, but are bound to no-op. This happens both in
  924. > Symantec C++ 6.0, using the glue from the THINK Ref 2.0, and in
  925. Metrowerks CW4.
  926. > I'm working on a Centris 650 running System 7.1, so I'm pretty sure my ROMs
  927. > contain that trap - could I be mistaken about this? Has anyone use
  928. gotten these
  929. > traps to work? Thanks,
  930.  
  931.  
  932. There is a certain "time" that these calls should be made so that they are
  933. associated with the current dialog. Otherwise, it could cause problems in
  934. the cases in which you don't want the system to do its thing for you.  
  935.  
  936. In other words, the effect is not global, but rather "contextual". 
  937. Example source code will show you what you need to know.
  938.  
  939. Hope this helps.
  940.  
  941. Mark Hanrek
  942.  
  943. +++++++++++++++++++++++++++
  944.  
  945. >From dirk@gaga.maschinenbau.uni-dortmund.de (Dirk Froehling)
  946. Date: Fri, 26 Aug 1994 09:41:03 +0100
  947. Organization: UniDO
  948.  
  949. In article <hanrek-2508941320100001@auke.cts.com>, hanrek@cts.com (Mark
  950. Hanrek) wrote:
  951.  
  952. > In article <SCOTTH.94Aug25094232@jaguar.visix.com>,
  953. > scotth@jaguar.visix.com (Scott Hofmann) wrote:
  954. > > In some code I've written for a preferences dialog, I use the calls
  955. > > SetDialogDefaultItem() and SetDialogCancelItem() to make my "OK" and 
  956. > There is a certain "time" that these calls should be made so that they are
  957. > associated with the current dialog.
  958.  
  959. Try something like (this is Pascal, but...):
  960.  
  961.         myDlog := GetNewDialog(myID, nil, pointer(-1));
  962.  
  963.         myErr := SetDialogDefaultItem(myDlog, OK);
  964.         myErr := SetDialogCancelItem(myDlog, cancel);
  965.  
  966.      { here it comes: }
  967.         myErr := GetStdFilterProc(filterIt); { don't use your own filter }
  968.  
  969.         repeat
  970.             ModalDialog(filterIt, itemHit);
  971.             { do something }
  972.         until itemHit in [OK, Cancel];
  973.  
  974. -- 
  975. | Dirk Froehling - Germany, Uni Dortmund, FB Maschinenbau, LS Mechanik |
  976. | dirk@gaga.maschinenbau.uni-dortmund.de            GEnie: D.FROEHLING |
  977.  
  978. +++++++++++++++++++++++++++
  979.  
  980. >From gbolsinga@aol.com (GBolsinga)
  981. Date: 26 Aug 1994 16:02:07 -0400
  982. Organization: America Online, Inc. (1-800-827-6364)
  983.  
  984. In article <dirk-260894094103@129.217.230.3>,
  985. dirk@gaga.maschinenbau.uni-dortmund.de (Dirk Froehling) writes:
  986.  
  987. >Try something like (this is Pascal, but...):
  988. >
  989. >  myDlog := GetNewDialog(myID, nil, pointer(-1));
  990. >
  991. >  myErr := SetDialogDefaultItem(myDlog, OK);
  992. >  myErr := SetDialogCancelItem(myDlog, cancel);
  993. >
  994. >  { here it comes: }
  995. >  myErr := GetStdFilterProc(filterIt); { don't use your own filter }
  996. >
  997. >  repeat
  998. >   ModalDialog(filterIt, itemHit);
  999. >   { do something }
  1000. >  until itemHit in [OK, Cancel];
  1001.  
  1002. You could use your own filter which pre-filters the call and then calls
  1003. the 
  1004. standard filter proc
  1005.  
  1006. Greg
  1007. MPI Multimedia
  1008. /* These are MY opinions */
  1009.  
  1010.  
  1011. +++++++++++++++++++++++++++
  1012.  
  1013. >From stk@uropax.contrib.de (Stefan Kurth)
  1014. Date: 27 Aug 1994 18:20:16 +0200
  1015. Organization: Contributed Software GbR
  1016.  
  1017. In article <33lhnv$m7r@search01.news.aol.com>,
  1018. GBolsinga <gbolsinga@aol.com> wrote:
  1019.  
  1020. > In article <dirk-260894094103@129.217.230.3>,
  1021. > dirk@gaga.maschinenbau.uni-dortmund.de (Dirk Froehling) writes:
  1022. >
  1023. > > { don't use your own filter }
  1024. >
  1025. > You could use your own filter which pre-filters the call and then calls
  1026. > the standard filter proc
  1027.  
  1028. Yes, but remember to call it like this:
  1029.  
  1030.     GetStdFilterProc(&theFilterProc);
  1031.  
  1032.     asm {
  1033.         move.l d3, -(a7)
  1034.     }
  1035.  
  1036.     result = theFilterProc(theDialog, &theEvent, &itemHit);
  1037.  
  1038.     asm {
  1039.         move.l (a7)+, d3
  1040.     }
  1041.  
  1042.     return result;
  1043.  
  1044. since the std filter proc trashes d3, which can cause strange things to
  1045. happen to your local variables.
  1046.  
  1047. ________________________________________________________________________
  1048. Stefan Kurth                 Berlin, Germany              stk@contrib.de
  1049.  
  1050. ---------------------------
  1051.  
  1052. >From woody@alumni.caltech.edu (William Edward Woody)
  1053. Subject: Trouble making floating windows work with modeless dialogs
  1054. Date: 26 Aug 1994 06:56:43 GMT
  1055. Organization: California Institute of Technology, Alumni Association
  1056.  
  1057.  
  1058. I'm having a problem making modeless dialogs work with floating windows.
  1059. The problem is with 'IsDialogEvent()' and 'DialogSelect()'.
  1060.  
  1061. When I receive the event from WaitNextEvent(), I first determine if the
  1062. event is for a modal dialog through 'IsDialogEvent()', and if it is,
  1063. I call my subroutine which gets the calls 'DialogSelect()' to process
  1064. the event, and then handle the control ID if DialogSelect returns TRUE.
  1065.  
  1066. The problem is that it seems that the modeless dialog is not being
  1067. processed correctly if there is a floating window up. I think what's
  1068. going on is that as the floating window is the frontmost window in the
  1069. WindowList, IsDialogEvent() and DialogSelect() do not handle mouseDown,
  1070. nullEvent, or keyDown events at all.
  1071.  
  1072. Kludging the system to put the dialog at the head of the WindowList
  1073. global for processing of the IsDialogEvent() and DialogSelect() routines
  1074. allows me to click on buttons, but edit fields are handled completely
  1075. wrong.
  1076.  
  1077. What I want to know is, what can I do to make IsDialogEvent() and
  1078. DialogSelect() work. (I don't want to use the GhostWindow global because
  1079. I may have more than one floating window up at once.) If I can't
  1080. make those routines work, then how can I replace the routines with
  1081. code of my own to handle dialog events?
  1082.  
  1083. I'm really stuck here, and I don't know where to turn. This is my last
  1084. hope.
  1085.  
  1086. advTHANKSance.
  1087.  
  1088.                         - Bill
  1089. -- 
  1090. o William Edward Woody      | "I'm shying from the light
  1091.   In Phase Consulting      |  I always loved the night
  1092.   337 West California #4  |  And now you offer me eternal darkness"
  1093.   Glendale, CA 91203      |          - Depeche Mode, "One Caress"
  1094.  
  1095. +++++++++++++++++++++++++++
  1096.  
  1097. >From woody@alumni.caltech.edu (William Edward Woody)
  1098. Date: 26 Aug 1994 22:19:16 GMT
  1099. Organization: California Institute of Technology, Alumni Association
  1100.  
  1101. a while ago (yesterday?) I wrote:
  1102. > I'm having a problem making modeless dialogs work with floating windows.
  1103. > The problem is with 'IsDialogEvent()' and 'DialogSelect()'.
  1104. > What I want to know is, what can I do to make IsDialogEvent() and
  1105. > DialogSelect() work. (I don't want to use the GhostWindow global because
  1106. > I may have more than one floating window up at once.) If I can't
  1107. > make those routines work, then how can I replace the routines with
  1108. > code of my own to handle dialog events?
  1109.  
  1110. Well, without a solution I could use fast enough, I bit the bullet and wrote
  1111. the routines MIsDialogEvent() and MDialogSelect() to replace IsDialogEvent()
  1112. and DialogSelect() to solve my problem.
  1113.  
  1114. I have attached the code I wrote below, so others can also do modeless
  1115. dialogs and floating windows at the same time.
  1116.  
  1117. NOTE:    In these routines below, MFrontWindow() is the replacement to
  1118.     FrontWindow() which figures out the frontmost non-floater window.
  1119.  
  1120. NOTE:    These routines are not well-tested. They work for me, but they
  1121.     may have bugs (some severe) which prevent their adequate use.
  1122.     Note that they were written to be used together, and are not
  1123.     compatable with their 'IsDialogEvent()/DialogSelect()' counterparts.
  1124.     I don't know why this is; it just is.
  1125.  
  1126. Code follows:
  1127.  
  1128. - -CUT HERE---CUT HERE---CUT HERE---CUT HERE---CUT HERE---CUT HERE---
  1129.  
  1130. /*  MIsDialogEvent
  1131.  *
  1132.  *    Is this an event for this dialog box?
  1133.  */
  1134.  
  1135. Boolean MIsDialogEvent(EventRecord *event)
  1136. {
  1137.     WindowPtr w;
  1138.     short where;
  1139.     
  1140.     switch (event->what) {
  1141.     case mouseDown:
  1142.         where = FindWindow(event->where,&w);
  1143.         if (where != inContent) w = NULL;
  1144.         else if (w != MFrontWindow()) w = NULL;
  1145.         break;
  1146.     case updateEvt:
  1147.     case activateEvt:
  1148.         w = (WindowPtr)(event->message);
  1149.         break;
  1150.     case keyDown:
  1151.     case autoKey:
  1152.     default:
  1153.         w = MFrontWindow();
  1154.         break;
  1155.     }
  1156.     if (w == NULL) return 0;
  1157.     if (((WindowPeek)w)->windowKind == dialogKind) return 1;
  1158.     return 0;
  1159. }
  1160.  
  1161. /*  MDialogSelect
  1162.  *
  1163.  *    Do the dialog select routines. This does all of the dialog
  1164.  *  processing stuff for this dialog window if it is one.
  1165.  */
  1166.  
  1167. Boolean MDialogSelect(EventRecord *event, DialogPtr *dlog, short *item)
  1168. {
  1169.     WindowPtr w;
  1170.     DialogPeek peek;
  1171.     short where;
  1172.     Handle h;
  1173.     Rect r;
  1174.     TEHandle text;
  1175.     char c;
  1176.     short index;
  1177.     short length;
  1178.     Point pt;
  1179.     long tmp;
  1180.     
  1181.     /*
  1182.      *  Determine the dialog window that is being used here.
  1183.      */
  1184.     
  1185.     switch (event->what) {
  1186.         case mouseDown:
  1187.         case mouseUp:
  1188.             where = FindWindow(event->where,&w);
  1189.             if (where != inContent) w = NULL;
  1190.             break;
  1191.         case updateEvt:
  1192.         case activateEvt:
  1193.             w = (WindowPtr)(event->message);
  1194.             break;
  1195.         default:
  1196.             w = MFrontWindow();
  1197.             break;
  1198.     }
  1199.     if (w == NULL) return 1;        // Not my event...
  1200.     if (((WindowPeek)w)->windowKind != dialogKind) return 1;
  1201.     
  1202.     /*
  1203.      *  Now, actually do this event as appropriate
  1204.      */
  1205.     
  1206.     *dlog = w;                // The dialog I was handling.
  1207.     *item = 0;                // Default item (0)
  1208.     peek = (DialogPeek)w;        // So I can get at internal stuff
  1209.     switch (event->what) {
  1210.     
  1211.         /*
  1212.          *  Activate/Deactivate
  1213.          *
  1214.          *    This activates or deactivates the text edit field
  1215.          *  if it is present in the dialog box.
  1216.          */
  1217.         
  1218.         case activateEvt:
  1219.             SetPort(w);
  1220.             text = peek->textH;
  1221.             if (text) {
  1222.                 if (event->modifiers & activeFlag) {
  1223.                     TEActivate(text);
  1224.                 } else {
  1225.                     TEDeactivate(text);
  1226.                 }
  1227.             }
  1228.             return 0;            // Further processing not needed
  1229.         
  1230.         /*
  1231.          *  Update
  1232.          *
  1233.          *    This simply draws the contents of this thing
  1234.          */
  1235.         
  1236.         case updateEvt:
  1237.             SetPort(w);
  1238.             BeginUpdate(w);
  1239.             UpdateDialog(w,w->visRgn);
  1240.             EndUpdate(w);
  1241.             return 0;            // Further processing not needed
  1242.         
  1243.         /*
  1244.          *  Null event processing
  1245.          *
  1246.          *    Blink the cursor
  1247.          */
  1248.         
  1249.         default:
  1250.         case nullEvent:
  1251.             SetPort(w);
  1252.             if (peek->textH) TEIdle(peek->textH);
  1253.             return 0;            // Further processing not needed
  1254.         
  1255.         /*
  1256.          *  Key events
  1257.          *
  1258.          *    This handles keyboard events by processing the enter/
  1259.          *  escape keys as buttons 1 and 2; otherwise, pass to the
  1260.          *  current edit box, if any.
  1261.          */
  1262.         
  1263.         case keyDown:
  1264.         case autoKey:
  1265.             SetPort(w);
  1266.             c = (unsigned char)(event->message & charCodeMask);
  1267.             
  1268.             /*
  1269.              *  Enter, escape processing
  1270.              */
  1271.             
  1272.             if ((c == 0x03) || (c == 0x0D) || (c == 0x1B)) {                
  1273.                 if ((c == 0x03) || (c == 0x0D)) {
  1274.                     *item = 1;
  1275.                 } else {
  1276.                     *item = 2;
  1277.                 }
  1278.                 
  1279.                 GetDialogItem(w,*item,&where,&h,&r);
  1280.                 HiliteControl((ControlHandle)h,inButton);
  1281.                 Delay(5,&tmp);
  1282.                 HiliteControl((ControlHandle)h,0);
  1283.                 return 1;        // Further processing needed
  1284.             }
  1285.             
  1286.             /*
  1287.              *  Tab processing
  1288.              */
  1289.             
  1290.             if (c == 0x09) {        // Horizontal tab key
  1291.                 if (peek->textH == NULL) return 0;    // Can't deal with it.
  1292.                 length = *((short *)(*(peek->items))) + 1;
  1293.                 index = peek->editField+2;        // Skip this one
  1294.                 
  1295.                 /*
  1296.                  *  Find the next edit item and select it
  1297.                  */
  1298.                 
  1299.                 while (index <= length) {
  1300.                     GetDialogItem(w,index,&where,&h,&r);
  1301.                     if ((0x7F & where) == 16) {        // This is an edit item
  1302.                         SelIText(w,index,0,32767);    // Move edit, select me
  1303.                         *item = index;
  1304.                         return ((where & 0x80) == 0) ? 1 : 0;
  1305.                     }
  1306.                     index++;
  1307.                 }
  1308.                 index = 1;                // Wrap to beginning
  1309.                 while (index <= length) {
  1310.                     GetDialogItem(w,index,&where,&h,&r);
  1311.                     if ((0x7F & where) == 16) {        // This is an edit item
  1312.                         SelIText(w,index,0,32767);    // Move edit, select me
  1313.                         *item = index;
  1314.                         return ((where & 0x80) == 0) ? 1 : 0;
  1315.                     }
  1316.                     index++;
  1317.                 }
  1318.                 *item = 0;
  1319.                 return 0;                // Huh? Dunno...
  1320.             }
  1321.             
  1322.             /*
  1323.              *  Normal keyboard processing
  1324.              */
  1325.             
  1326.             text = peek->textH;
  1327.             if (text == NULL) return 0;            // No edit item to do
  1328.             
  1329.             *item = peek->editField+1;            // Item ID we're doing
  1330.             TEKey(c,text);                // Do character process
  1331.             
  1332.             GetDialogItem(w,*item,&where,&h,&r);    // Return appropriate
  1333.             return ((where & 0x80) == 0) ? 1 : 0;    // for enable flag
  1334.         
  1335.         /*
  1336.          *  Mouse down:
  1337.          *
  1338.          *    track the controls or the edit fields as appropriate
  1339.          */
  1340.         
  1341.         case mouseDown:
  1342.             SetPort(w);
  1343.             pt = event->where;
  1344.             GlobalToLocal(&pt);
  1345.             
  1346.             /*
  1347.              *  Determine where the mouse went down
  1348.              */
  1349.             
  1350.             index = FindDItem(w,pt)+1;
  1351.             if (index == 0) return 0;        // Not on anything
  1352.             GetDialogItem(w,index,&where,&h,&r);
  1353.             *item = index;
  1354.             
  1355.             /*
  1356.              *  Handle inactive objects
  1357.              */
  1358.             
  1359.             if (where & 0x80) {
  1360.                 if (where == 0x90) {        // Edit item here.
  1361.                 
  1362.                     /*
  1363.                      *  Handle edit selection even if inactive
  1364.                      */
  1365.                     
  1366.                     if (peek->editField + 1 != index) {
  1367.                         SelIText(w,index,0,32767);
  1368.                     }
  1369.                     TEClick(pt,(event->modifiers & shiftKey) ? 1 : 
  1370. 0,peek->textH);
  1371.                 }
  1372.                 return 0;
  1373.             }
  1374.             
  1375.             /*
  1376.              *  Process according to where I'm at
  1377.              */
  1378.             
  1379.             switch (where) {
  1380.                 default:
  1381.                     return 1;            // Just return the ID.
  1382.                 case 4:
  1383.                 case 5:
  1384.                 case 6:
  1385.                 case 7:
  1386.                     /*
  1387.                      *  Click on a standard control object
  1388.                      */
  1389.                     
  1390.                     if (TrackControl((ControlHandle)h,pt,NULL)) return 1; // do 
  1391. it.
  1392.                     return 0;            // don't do it.
  1393.                 case 16:            // Handle edit box
  1394.                     if (peek->editField + 1 != index) {
  1395.                         SelIText(w,index,0,32767);
  1396.                     }
  1397.                     TEClick(pt,(event->modifiers & shiftKey) ? 1 : 
  1398. 0,peek->textH);
  1399.                     return 1;            // Return where I am now. 
  1400.             }
  1401.     }
  1402.     return 0;        // Not one of these; can't deal with it at all...
  1403. }
  1404.  
  1405. - -CUT HERE---CUT HERE---CUT HERE---CUT HERE---CUT HERE---CUT HERE---
  1406.  
  1407. I hope this helps. Permission is granted to use this message and the
  1408. code contained herein in any way you want, redistribute it, fold it,
  1409. spindle it, or mutulate it, so long as you don't sue me if the code
  1410. crashes. Given away as is, without warranty of any kind. If you don't
  1411. like this, my lawyer can mud-wrestle your lawyer in the nude for 15
  1412. rounds at the local mud-wrestling bar for brownies. (This assumes,
  1413. of course, that your lawyer and my lawyer look good in the nude. :-)
  1414.  
  1415.                         - Bill
  1416. -- 
  1417. o William Edward Woody      | "I'm shying from the light
  1418.   In Phase Consulting      |  I always loved the night
  1419.   337 West California #4  |  And now you offer me eternal darkness"
  1420.   Glendale, CA 91203      |          - Depeche Mode, "One Caress"
  1421.  
  1422. ---------------------------
  1423.  
  1424. End of C.S.M.P. Digest
  1425. **********************
  1426.  
  1427.  
  1428.